home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / C++SIM / thread.cc < prev    next >
C/C++ Source or Header  |  1993-06-14  |  1KB  |  66 lines

  1. /*
  2.  * Copyright (C) 1993
  3.  *
  4.  * Department of Computing Science,
  5.  * The University,
  6.  * Newcastle upon Tyne,
  7.  * UK.
  8.  */
  9.  
  10. #ifndef THREAD_H_
  11. #include "thread.h"
  12. #endif
  13.  
  14.  
  15. class Thread *Thread::head = 0; // Initialise head of Thread list
  16.  
  17.  
  18. Thread::Thread ()
  19. {
  20.     Thread *marker = head;
  21.  
  22.     if (head != 0)
  23.     {
  24.     while (marker->next != 0)
  25.         marker = marker->next;
  26.  
  27.     marker->next = this;
  28.     marker->next->prev = marker;
  29.     marker = marker->next;
  30.     marker->next = 0;
  31.     }
  32.     else
  33.     {
  34.     this->prev = 0;
  35.     this->next = 0;
  36.     head = this;
  37.     }
  38.  
  39.     thread_key = 0;
  40.     // Actual thread key value MUST be set in derived class constructor
  41. }
  42.  
  43. Thread::~Thread ()
  44. {
  45.     if (this->prev != 0)
  46.     this->prev->next = this->next;
  47.     else
  48.     head = this->next;
  49. }
  50.  
  51. long Thread::Identity () const { return thread_key; }
  52.  
  53. Thread *Thread::Self ()
  54. {
  55.     if (!head) return 0;
  56.  
  57.     // Use any thread object (e.g., head) to get access to the current thread
  58.     long my_id = head->Current_Thread();
  59.  
  60.     for (Thread *marker = head; marker; marker=marker->next)
  61.     if (marker->thread_key == my_id)
  62.         break;
  63.  
  64.     return marker;
  65. }
  66.